/**
 * 
 */
package com.xbang.attendance.web.action.region.sgmregion;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.xbang.attendance.entity.system.Region;
import com.xbang.attendance.service.SystemService;
import com.demo2do.lighturl.annotation.Action;
import com.xbang.core.page.Result;
import com.xbang.core.struts.support.BaseActionSupport;
import com.xbang.core.struts.support.SearchActionSupport;

import enumeration.RegionType;

/**
 * @author dev.zhang
 * 
 */
public class Search extends SearchActionSupport {

	private static final long serialVersionUID = -2293665695731096858L;

	private Log logger = LogFactory.getLog(Search.class);

	@Autowired
	private SystemService systemService;

	private List<Region> regions = new ArrayList<Region>();

	public String execute() throws Exception {
		return "search";
	}

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	@Action("/region/sgmregion/search/do")
	public String doSearch() throws Exception {

		String hqlSentence = "FROM Region region WHERE 1 = 1 ";
		searchComponent.addSearchElement("eq.region.regionType", RegionType.SGM);
		Result result = systemService.searchByPage(hqlSentence, searchComponent, page);

		regions = result.getItems();
		page = result.getPage();

		return "index";
	}

	@Override
	public void resetCustomerSearchCriteria() {
		// TODO Auto-generated method stub

	}

	/**
	 * @return the regions
	 */
	public List<Region> getRegions() {
		return regions;
	}

	/**
	 * @param regions
	 *            the regions to set
	 */
	public void setRegions(List<Region> regions) {
		this.regions = regions;
	}

}
